//
//  DingdanxiangqingneirongViewController.m
//  tianjin
//
//  Created by 鞠超 on 16/8/13.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "DingdanxiangqingneirongViewController.h"

#import "ShangpinqingdanViewController.h"

@interface DingdanxiangqingneirongViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;

//
@property (nonatomic, strong) UILabel * name_user;
@property (nonatomic, strong) UILabel * tel_user;
@property (nonatomic, strong) UILabel * address_user;
//
//布局
@property (nonatomic, strong) UIImageView * image_1;
@property (nonatomic, strong) UIImageView * image_2;
@property (nonatomic, strong) UILabel * price_product;
@property (nonatomic, strong) UILabel * number;
//运费
@property (nonatomic, strong) UILabel * price_peisong;
//留言
@property (nonatomic, strong) UILabel * text_liuyan;
//支付
@property (nonatomic, strong) UILabel * zhifu_type;

@end

@implementation DingdanxiangqingneirongViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void)p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    _topView.backgroundColor = [UIColor blackColor];
    
    _lblTitle.text = @"订单详情";
    _lblTitle.textColor = [UIColor whiteColor];
    _lblTitle.font = [UIFont systemFontOfSize:19];
    
    UIImageView * image_return = [[UIImageView alloc] initWithFrame:CGRectMake(15, 32, 10, 20)];
    image_return.image = [UIImage imageNamed:@"zuofanhui@2x.png"];
    [_topView addSubview:image_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 20, 35, 44);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    //tableview
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:self.tableView];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        return 85;
    }
    else if(indexPath.row == 1)
    {
        return 100;
    }
    else if(indexPath.row == 2 || indexPath.row == 3 || indexPath.row == 4)
    {
        return 50;
    }
    else if(indexPath.row == 5)
    {
        return 30;
    }
    else
    {
        return 400;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] init];
 
    if(indexPath.row == 0)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        UIImageView * image_dizhi = [[UIImageView alloc] initWithFrame:CGRectMake(10, 25, 15, 20)];
        image_dizhi.image = [UIImage imageNamed:@"dingdan_dizhi@2x.png"];
        [cell addSubview:image_dizhi];
        
//        UIImageView * image_fanhui = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 10 - 10, 27.5, 10, 15)];
//        image_fanhui.image = [UIImage imageNamed:@"dizhi_fanhui@2x.png"];
//        [cell addSubview:image_fanhui];
        
        CGFloat length_x = (SCREEN_WIDTH - CGRectGetMaxX(image_dizhi.frame) - 10 - 10) / 2;
        
        self.name_user = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_dizhi.frame) + 10, 15, length_x, 15)];
        self.name_user.text = @"sdjksjksjkjkjdksj";
        self.name_user.font = [UIFont systemFontOfSize:15];
        [cell addSubview:self.name_user];
        
        self.tel_user = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.name_user.frame),  15, length_x, 15)];
        self.tel_user.text = @"12345678988";
        self.tel_user.font = [UIFont systemFontOfSize:15];
        self.tel_user.textAlignment = NSTextAlignmentRight;
        [cell addSubview:self.tel_user];
        
        self.address_user = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_dizhi.frame) + 10, CGRectGetMaxY(self.name_user.frame) + 15, length_x * 2, 15)];
        self.address_user.font = [UIFont systemFontOfSize:15];
        self.address_user.text = @"山东省临沂市兰山区山东省临沂市兰山区";
        [cell addSubview:self.address_user];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.address_user.frame) + 15, SCREEN_WIDTH, 10)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];        
    }
    else if(indexPath.row == 1)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.image_1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 70, 70)];
        [self.image_1 sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"chanpingPic@2x.png"]];
        [cell addSubview:self.image_1];
        
        self.image_2 = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.image_1.frame) + 10, 10, 70, 70)];
        [self.image_2 sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"chanpingPic@2x.png"]];
        [cell addSubview:self.image_2];
        
        //
        self.price_product = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.image_2.frame) + 10, 25, SCREEN_WIDTH - CGRectGetMaxX(self.image_2.frame) - 10 - 30, 20)];
        self.price_product.textAlignment = NSTextAlignmentRight;
        self.price_product.text = @"￥1009.9";
        self.price_product.textColor = [UIColor redColor];
        self.price_product.font = [UIFont systemFontOfSize:17];
        [cell addSubview:self.price_product];
        
        self.number = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.image_2.frame) + 10, CGRectGetMaxY(self.price_product.frame) + 10, SCREEN_WIDTH - CGRectGetMaxX(self.image_2.frame) - 10 - 30, 15)];
        self.number.textColor = [UIColor grayColor];
        self.number.textAlignment = NSTextAlignmentRight;
        self.number.font = [UIFont systemFontOfSize:15];
        self.number.text = @"共20件";
        [cell addSubview:self.number];
        
        UIImageView * image_fanhui = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 10 - 10, 37.5, 10, 15)];
        image_fanhui.image = [UIImage imageNamed:@"dizhi_fanhui@2x.png"];
        [cell addSubview:image_fanhui];
        
        UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(0, 90, SCREEN_WIDTH, 10)];
        view_line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_line];
    }
    else if(indexPath.row == 2)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 70, 20)];
        name.text = @"配送信息:";
        name.font = [UIFont systemFontOfSize:16];
        [cell addSubview:name];
        
        self.price_peisong = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame) + 10, 17.5, SCREEN_WIDTH - CGRectGetMaxX(name.frame) - 20, 15)];
        self.price_peisong.text = @"配送费20元";
        self.price_peisong.font = [UIFont systemFontOfSize:16];
        self.price_peisong.textColor = [UIColor grayColor];
        [cell addSubview:self.price_peisong];
        
        UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(0, 49, SCREEN_WIDTH, 1)];
        view_line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_line];
    }
    else if(indexPath.row == 3)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 70, 20)];
        name.text = @"支付方式:";
        name.font = [UIFont systemFontOfSize:16];
        [cell addSubview:name];
        
        self.zhifu_type = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame) + 10, 17.5, SCREEN_WIDTH - CGRectGetMaxX(name.frame) - 20, 15)];
        self.zhifu_type.text = @"微信支付";
        self.zhifu_type.font = [UIFont systemFontOfSize:16];
        self.zhifu_type.textColor = [UIColor grayColor];
        [cell addSubview:self.zhifu_type];
        
        UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(0, 49, SCREEN_WIDTH, 1)];
        view_line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_line];
    }
    else if(indexPath.row == 4)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 70, 20)];
        name.text = @"买家留言:";
        name.font = [UIFont systemFontOfSize:16];
        [cell addSubview:name];
        
        self.text_liuyan = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame) + 10, 17.5, SCREEN_WIDTH - CGRectGetMaxX(name.frame) - 20, 15)];
        self.text_liuyan.text = @"无";
        self.text_liuyan.font = [UIFont systemFontOfSize:16];
        self.text_liuyan.textColor = [UIColor grayColor];
        [cell addSubview:self.text_liuyan];
        
        UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(0, 49, SCREEN_WIDTH, 1)];
        view_line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_line];
    }
    else if(indexPath.row == 5)
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UIView * view_line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 5)];
        view_line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_line];
        
        UIView * view_line1 = [[UIView alloc] initWithFrame:CGRectMake(0, 5, SCREEN_WIDTH, 25)];
        view_line1.backgroundColor = [UIColor colorWithRed:222.0/255.0 green:222.0/255.0  blue:222.0/255.0 alpha:1.0f];
        [cell addSubview:view_line1];
        
        UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(10, 5 + 3, 70, 20)];
        name.text = @"订单状态";
        name.font = [UIFont systemFontOfSize:16];
        [cell addSubview:name];
    }
    else
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
    }
    
    
    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 1)
    {
        ShangpinqingdanViewController * shangpinqingdanViewController = [[ShangpinqingdanViewController alloc] init];
        [self showViewController:shangpinqingdanViewController sender:nil];
    }
}
















@end
